import request from '@/utils/request';
import type {
    HasSpuResponseData,
    AllTradeMark,
    SpuPicData,
    SaleAttrData,
    BaseSaleAttrData,
    SpuDate,
    SkuData,
    skuInfoData,
} from './type';
enum API {
    HASSPU_API = '/admin/product',
    // 获取所有品牌数据
    ALLTRADEMARK_API = '/admin/product/baseTrademark/getTrademarkList',
    // 获取 spu 图片
    SPUPIC_API = '/admin/product/spuImageList',
    // 获取某一个 spu 下已有的销售属性
    SPUSALEATTR_API = '/admin/product/spuSaleAttrList',
    // 获取所有的销售属性
    BASESALEATTR_API = '/admin/product/baseSaleAttrList',
    // 增加一个新的 spu
    ADDSPU_API = '/admin/product/saveSpuInfo',
    // 更新一个 spu
    UPDATESPU_API = '/admin/product/updateSpuInfo',
    //追加一个新的 sku
    ADDSKU_API = '/admin/product/saveSkuInfo',
    // 查看某一个spu 下全部的 sku
    SKU_LIST_API = '/admin/product/findBySpuId',
    // 删除 spu
    DELETESPU_API = '/admin/product/deleteSpu',
}
export const reqHsaSpu = (
    page: number,
    limit: number,
    category3Id: string | number,
) =>
    request.get<any, HasSpuResponseData>(
        API.HASSPU_API + `/${page}/${limit}?category3Id=${category3Id}`,
    );

// 获取所有 spu 品牌数据
export const reqAllTrademark = () =>
    request.get<any, AllTradeMark>(API.ALLTRADEMARK_API);

// 获取 spu 图片
export const reqSpuPic = (spuId: number) =>
    request.get<any, SpuPicData>(API.SPUPIC_API + `/${spuId}`);

// 获取某一个 spu 下已有的销售属性
export const reqSpuSaleAttr = (spuId: number) =>
    request.get<any, SaleAttrData>(API.SPUSALEATTR_API + `/${spuId}`);

// 获取所有的销售属性
export const reqBaseSaleAttr = () =>
    request.get<any, BaseSaleAttrData>(API.BASESALEATTR_API);

// 增加一个新的 spu 或更新一个 spu
export const reqAddOrUpdateSpu = (data: SpuDate) => {
    if (data.id) {
        return request.post<any, any>(API.UPDATESPU_API, data);
    } else {
        return request.post<any, any>(API.ADDSPU_API, data);
    }
};
// 添加 sku
export const reqAddSku = (data: SkuData) =>
    request.post<any, any>(API.ADDSKU_API, data);

// 查看某一个 spu 下全部的 sku
export const reqSkuList = (spuId: number) =>
    request.get<any, skuInfoData>(API.SKU_LIST_API + `/${spuId}`);

// 删除 spu
export const reqDeleteSpu = (spuId: number) =>
    request.delete<any, any>(API.DELETESPU_API + `/${spuId}`);
